package cn.itsource.controller;

import cn.itsource.domain.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private ApplicationContext context;
    @GetMapping("/{id}")
    public Order getById(@PathVariable("id") Long id){
        String[] activeProfiles = context.getEnvironment().getActiveProfiles();
        if (activeProfiles!=null && activeProfiles.length>0)
            //正常来说要调用Service，进而调用Mapper，从数据库获取，但是现在我们直接new返回
            return new Order(1L,"199套餐"+activeProfiles[0]);
        else
            return new Order(1L,"199套餐");
    }
}

